classDiagram
    class DealerApplicationService {
        <<应用服务>>
        -DealerRepository dealerRepository
        -DealerNameUniquenessCheckService dealerNameUniquenessCheckService

        +create(DealerCreateCommand, DealerCreateCommandResult) void
        +changeName(DealerChangeNameCommand) void
        +changeTelephone(DealerChangeTelephoneCommand) void
        +changeAddress(DealerChangeAddressCommand) void
        +makeDealerHidden(ChangeDealerVisibilityCommand) void
        +makeDealerVisible(ChangeDealerVisibilityCommand) void
        +updateServiceTimeOnServicePurchaseOrderPaid(\n&nbsp;&nbsp;UpdateServiceTimeOnServicePurchaseOrderPaidCommand) void
    }

%%    note for DealerCreateCommand "用于应用服务方法传参"
    class DealerCreateCommand {
        <<Command>>
    }

%%    note for DealerCreateCommandResult "用于外部接收应用服务方法操作结果"
    class DealerCreateCommandResult {
        <<接口>>
        +resultingDealerId(long) void
    }

    note for DealerApplicationService "1. 方法返回类型 void\n2. 方法参数使用 Command\n3. 使用 CommandResult 向外传递值"

    class Dealer {
        <<聚合根>>
        -DealerId id
        -String name
        -String telphone
        -DealerVisibilityStatusType visibilityStatus
        -DealerServiceStatusType serviceStatus
        -LocalDateTime serviceExpiryTime

        +Dealer(...)
        +Dealer(...)

        +changeName(name,DealerNameUniquenessCheckService) void
        +changeAddress(Address) void
        +changeTelephone(telephone) void
        +makeDealerVisible() void
        +makeDealerHidden() void
        +updateServiceTime(nextServiceExpiryTime) void

        +snapshot() DealerSnapshot
    }

    class DealerSnapshot

    note for DealerDatabaseModel "和数据库表对应"
    class DealerDatabaseModel {
        <<DatabaseModel>>
    }

    class DealerRepository["DealerRepository 接口"] {
        <<接口>>
        +nextId() DealerId
        +findById(DealerId) Dealer
        +findByName(name) Dealer
        +save(Dealer) void
    }

    class MyBatisDealerRepository {
        <<资源库>>
        -DealerMapper
        -IdGenerator idGenerator

        +nextId() DealerId
        +findById(DealerId) Dealer
        +findByName(name) Dealer
        +save(Dealer) void
    }

    class IdGenerator {
        <<接口>>
        nextId() long
    }

    class SnowflakeIdGenerator

    class DealerMapper {
        <<接口>>
        insertOrIgnore(DealerDatabaseModel) int
        update(DealerDatabaseModel) int
        selectById(long) DealerDatabaseModel
        selectByName(String) DealerDatabaseModel
    }

    class DealerNameUniquenessCheckService {
        <<领域服务>>
        +isNameNotUsed(name) boolean
        +isNameNotUsed(name, excludeDealerId) boolean
    }

    class DealerCreated {
        <<领域事件>>
    }

    class DealerInfoUpdated {
        <<领域事件>>
    }

    class DealerVisibilityChanged {
        <<领域事件>>
    }

    class DealerServiceChanged {
        <<领域事件>>
    }

    DealerApplicationService ..> DealerCreateCommand
    DealerApplicationService ..> DealerCreateCommandResult
    DealerApplicationService ..> Dealer
    DealerApplicationService ..> DealerRepository
    DealerApplicationService ..> DealerNameUniquenessCheckService
    Dealer ..> DealerNameUniquenessCheckService: 通过依赖领域服务保证数据状态一致性
    DealerRepository ..> Dealer
    DealerNameUniquenessCheckService ..> DealerRepository

    Dealer ..> DealerCreated: Dealer()
    Dealer ..> DealerInfoUpdated: changeName()\n changeAddress()\n changeTelephone()
    Dealer ..> DealerVisibilityChanged: makeDealerVisible()\n makeDealerHidden()
    Dealer ..> DealerServiceChanged: updateServiceTime()

    DealerRepository <|.. MyBatisDealerRepository
    MyBatisDealerRepository ..> DealerMapper
    DealerMapper ..> DealerDatabaseModel
    MyBatisDealerRepository ..> DealerSnapshot
    Dealer ..> DealerSnapshot: 完整数据通过快照暴露

    IdGenerator <|.. SnowflakeIdGenerator: 雪花算法 ID 实现
    MyBatisDealerRepository ..> IdGenerator